package com.xjscrm.console.web.chat;

import com.xjscrm.common.exception.BusinessException;
import com.xjscrm.console.common.util.LoginContext;
import com.xjscrm.console.dto.chat.ChatTalkSessionOptDTO;
import com.xjscrm.console.dto.chat.ChatTalkSessionQueryDTO;
import com.xjscrm.console.service.customer.chat.ChatTalkSessionService;
import com.xjscrm.console.vo.LoginVO;
import com.xjscrm.console.vo.chat.ChatTalkSessionDeviceVO;
import com.xjscrm.console.vo.chat.ChatTalkSessionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @author mingyang.chen create in 2024/3/15 11:54
 */
@Api(value = "屏蔽聊天管理", tags = "聊天设置|屏蔽聊天管理")
@RestController
@RequestMapping("/chat/shield_session")
public class ChatShieldSettingConfController {

    @Autowired
    private ChatTalkSessionService chatTalkSessionService;


    @PostMapping("/search")
    @ApiOperation(value = "查询屏蔽的会话列表", notes = "查询屏蔽的会话列表", response = ChatTalkSessionVO.class)
    public Object search(@RequestBody ChatTalkSessionQueryDTO query) {
        if (Objects.isNull(query)) {
            throw new BusinessException("查询参数错误");
        }
        LoginVO login = LoginContext.getLogin();
        query.setOpenShield(1);
        return chatTalkSessionService.search(login, query);
    }

    @PostMapping("/device/list")
    @ApiOperation(value = "查询屏蔽的机器人列表", notes = "查询屏蔽的机器人列表", response = ChatTalkSessionDeviceVO.class)
    public Object listDevice() {
        LoginVO login = LoginContext.getLogin();
        return chatTalkSessionService.listDevice(login);
    }

    @PostMapping("/removeShield")
    @ApiOperation(value = "解除会话的屏蔽", notes = "解除会话的屏蔽", response = Boolean.class)
    public Object removeShield(@RequestBody ChatTalkSessionOptDTO opt) {
        LoginVO login = LoginContext.getLogin();
        return chatTalkSessionService.removeShield(login, opt.getIds());
    }

    @PostMapping("/syncShield")
    @ApiOperation(value = "同步屏蔽的会话", notes = "同步屏蔽的会话", response = Boolean.class)
    public Object syncShield(@RequestBody ChatTalkSessionOptDTO opt) {
        LoginVO login = LoginContext.getLogin();
        return chatTalkSessionService.syncShield(login, opt.getIds(), opt.getDeviceUniqueIds());
    }
}
